package com.hzqy.service.weather;

import com.hzqy.commons.utils.PublicUtil;
import com.hzqy.persistence.dao.weather.WeatherForecastDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.service.externalLink.ExternalLinkServiceBean;
import com.hzqy.web.vo.WlContentVo;
import com.hzqy.web.vo.weather.WeatherForecastVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WeatherForecastServiceBean extends GenericServiceBean<WeatherForecastVo,WeatherForecastDao, Integer>{
	
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private WeatherForecastDao weatherForecastDao;
	@Resource
	private ExternalLinkServiceBean externalLinkServiceBean;
	
	@Override
	public WeatherForecastDao getEntityDao() {
		return weatherForecastDao;
	}
	
	public WeatherForecastVo selectWeatherForecastVo(WeatherForecastVo vo){
		WlContentVo wlContentVo = new WlContentVo();
		wlContentVo.setF_wlc_name("前台天气总开关");
		wlContentVo.setSysConfigKey("control_link_ab");
		WlContentVo wlc = externalLinkServiceBean.selectWLContentAvaliable(wlContentVo);//是否可以访问
		if(wlc!=null){
			WeatherCacheUtil wcu = new WeatherCacheUtil(weatherForecastDao);
			String dateTime = PublicUtil.getCurDateTime("YYYY-MM-dd");
			vo.setF_wf_date(dateTime);
			vo = weatherForecastDao.selectWeatherForecastVo(vo);
			if(vo==null)
				vo = new WeatherForecastVo();
			LOG.debug("wfdate:"+vo.getF_wf_date()+";weather:"+vo.getF_wf_weather());
		}else{
			vo = new WeatherForecastVo();
		}
		return vo;
	}

}
